/**
 * Created by Administrator on 2016/2/14.
 */
$(function () {
    $("#baseToDetail").click(function () {
        //校验信息
        if (!$("#uploadTheme").val()) {
            CK.alert("活动主题未填写！");
            $("#uploadTheme").addClass("has-error");
            return;
        }
        if (!$("#dateStart").val() || !$("#dateEnd").val()
            || !$("#timeStart").val() || !$("#timeEnd").val()) {
            CK.alert("活动时间未填写！");
            //$("#uploadTheme").addClass("has-error");
            return;
        }
        if (!$("#deadlineDate").val() || !$("#deadlineTime").val() ) {
            CK.alert("报名截止日期未填写！");
            //$("#uploadTheme").addClass("has-error");
            return;
        }
        if (!$("#uploadCity").val() || !$("#uploadLocation").val()) {
            CK.alert("活动地点未填写！");
            //$("#uploadTheme").addClass("has-error");
            return;
        }
        var start = $("#dateStart").val()+" "+$("#timeStart").val();
        var end = $("#dateEnd").val()+" "+$("#timeEnd").val();
        if(start > end){
            CK.alert("起始时间不能小于结束时间未填写！");
            return;
        }
        //缓存信息
        config.uploadData.theme = $("#uploadTheme").val();
        config.uploadData.dateStart = $("#dateStart").val();
        config.uploadData.dateEnd = $("#dateEnd").val();
        config.uploadData.timeStart = $("#timeStart").val();
        config.uploadData.timeEnd = $("#timeEnd").val();
        config.uploadData.deadlineDate = $("#deadlineDate").val();
        config.uploadData.deadlineTime = $("#deadlineTime").val();
        config.uploadData.city = $("#uploadCity").val();
        config.uploadData.location = $("#uploadLocation").val();
        config.uploadData.upbound = $("#upbound").val();
        if(config.uploadData.type == 2){
            config.uploadData.school = $("#uploadSchool").val() ;
        }
        CK.load("html/upLoadActivity/detailInfo",$("#uploadContainer"));
    });
    //初始化数据
    if(config.uploadData){
        if(config.uploadData.type == 2){
            //校园活动
            var tplSchool = _.template($("#tpl_schoolAtv_position").html());
            $("#atvPosition").html(tplSchool());
        }else{
            //同城活动
            var tplCity = _.template($("#tpl_cityAtv_position").html());
            $("#atvPosition").html(tplCity());
        }
          $("#uploadTheme").val(config.uploadData.theme) ;
          $("#dateStart").val(config.uploadData.dateStart);
          $("#dateEnd").val(config.uploadData.dateEnd);
         $("#timeStart").val(config.uploadData.timeStart );
        $("#timeEnd").val(config.uploadData.timeEnd);
         $("#deadlineDate").val(config.uploadData.deadlineDate );
        $("#deadlineTime").val(config.uploadData.deadlineTime) ;
         $("#uploadCity").val(config.uploadData.city);
         $("#uploadLocation").val(config.uploadData.location);
         $("#upbound").val(config.uploadData.upbound ) ;
        if(config.uploadData.type == 2){
            $("#uploadSchool").val(config.uploadData.school ) ;
        }
    }

});
